package com.rtech.ds.tree;

public abstract class Tree {

	private Node root;

	Tree() {

	}

	Tree(Node tree) {
		root = tree;
	}

	public Node find(int key) {
		Node current = root;
		while (current.key != key) {
			if(current.key < key) {
				current = current.leftChild;
			} else {
				current = current.rightChild;
			}
			if(current == null) {
				return null;
			}
		}
		return current;
	}

	public void insert(int key, int value) {
		Node newNode = new Node();
		newNode.key = key;
		newNode.data = value;
		if(root == null) {
			root = newNode;
		}else {
			Node current = root;
			Node parent;
			while(true) {
				parent = current;
				if(key < current.key) {
					current = current.leftChild;
					if(current == null) {
						parent.leftChild = newNode;
						return;
					}
				} else {
					current = current.rightChild;
					if(current == null) {
						parent.rightChild = newNode;
						return;
					}
				}
				
			} // end of while
		} // end of else 
	}

	abstract void delete(int key);
}
